Class Img extends Box
public var src;
public var loadSrc;
public var loadSize;
public var frame=1;
function Img(src){
	if(this.__class==Img&&src){
		var resArr=IO.resHash[src];
		if(resArr){
			this.enabled=false;
			this.src=src;
			var extra=resArr[1];
			this.w=resArr[2];
			this.h=resArr[3];
			var n=extra.indexOf("/");
			var ext=n==-1?"png":extra.slice(n+1);
			var filePath=IO.resPath+src.replace(/\./g,"/")+"."+ext+"?"+resArr[1];
			this.div.style.cssText="pointer-events:none;width:"+this.w+"px;height:"+this.h+"px;background-image:url("+filePath+")";
			return;
		}
		this.setSrc(src);
	}
	this.setEnabled(false);
}
public function resetSelf(){
	var src=this.src;
	if(!src) return;
	if(src.indexOf("/")>-1){
		this.div.style.width=this.w+"px";
		this.div.style.height=this.h+"px";
		this.div.style.backgroundImage="url("+src+")";
		this.div.style.backgroundSize=this.w+"px "+this.h+"px";
		return;
	}
	var resArr=IO.resHash[src];
	if(!resArr||this.w==0||this.h==0){
		this.div.style.width="0px";
		this.div.style.height="0px";
		this.div.style.backgroundImage="none";
		return;
	}
	var extra=resArr[1];
	var w0=resArr[2];
	var h0=resArr[3];
	var w=this.w;
	var h=this.h;
	this.div.style.width=w+"px";
	this.div.style.height=h+"px";
	this.w=w;
	this.h=h;
	var style=G.style[src];
	var g=style?style.grid9:null;
	if(!g&&src.slice(-1)=="@"){
		style=G.style[src.slice(0,-1)];
		g=style?style.grid9:null;
	}
	if(extra.charAt(0)=="("){
		var baseSrc=extra.slice(1,-1);
		var resArr2=IO.resHash[baseSrc];
		var baseW=resArr2[2];
		var baseH=resArr2[3];
		var shiftX=resArr[6];
		var shiftY=resArr[7];
	}
	else{
		baseSrc=src;
		baseW=w0;
		baseH=h0;
		shiftX=0;
		shiftY=0;
	}
	var n=extra.indexOf("/");
	var ext=n==-1?"png":extra.slice(n+1);
	var filePath=IO.resPath+baseSrc.replace(/\./g,"/")+"."+ext+"?"+resArr[1];
	if(!g){
		this.div.style.backgroundImage="url("+filePath+")";
		this.div.style.backgroundPosition=(-shiftX*w/w0)+"px "+(-shiftY*h/h0)+"px";
		this.div.style.backgroundSize=(baseW*w/w0)+"px "+(baseH*h/h0)+"px";
		return;
	}
	if(g[2]==null) g[2]=0;
	if(g[3]==null) g[3]=0;
	var w=Math.max(w,g[0]+g[1]);
	var h=Math.max(h,g[2]+g[3]);
	var arr=[
		[0,0,g[0],g[2],							0,0,g[0],g[2]],
		[w0-g[1],0,g[1],g[2],					w-g[1],0,g[1],g[2]],
		[0,h0-g[3],g[0],g[3],					0,h-g[3],g[0],g[3]],
		[w0-g[1],h0-g[3],g[1],g[3],				w-g[1],h-g[3],g[1],g[3]],
		[g[0],0,w0-g[0]-g[1],g[2],				g[0],0,w-g[0]-g[1],g[2]],
		[0,g[2],g[0],h0-g[2]-g[3],				0,g[2],g[0],h-g[2]-g[3]],
		[w0-g[1],g[2],g[1],h0-g[2]-g[3],		w-g[1],g[2],g[1],h-g[2]-g[3]],
		[g[0],h0-g[3],w0-g[0]-g[1],g[3],		g[0],h-g[3],w-g[0]-g[1],g[3]],
		[g[0],g[2],w0-g[0]-g[1],h0-g[2]-g[3],	g[0],g[2],w-g[0]-g[1],h-g[2]-g[3]]
	];
	var index=0;
	for(var i=0;i<arr.length;i++){
		var a=arr[i];
		if(a[2]==0||a[3]==0) continue;
		if(a[6]<=0||a[7]<=0) continue;
		var span=this.children[index++];
		if(!span){
			span=document.createElement("span");
			this.div.appendChild(span);
			span.style.position="absolute";
			span.style.backgroundRepeat="no-repeat";
		}
		span.style.left=a[4]+"px";
		span.style.top=a[5]+"px";
		span.style.width=a[6]+"px";
		span.style.height=a[7]+"px";
		span.style.backgroundImage="url("+filePath+")";
		span.style.backgroundPosition=(-int(shiftX+a[0])*a[6]/a[2])+"px "+(-int(shiftY+a[1])*a[7]/a[3])+"px";
		span.style.backgroundSize=Math.ceil(baseW*a[6]/a[2])+"px "+Math.ceil(baseH*a[7]/a[3])+"px";
	}
}
public function setSize(w,h){
	Box.proto.setSize.call(this,w,h);
	this.changeSelf();
}
public function setSrc(v){
	if(!v) return;
	this.src=v;
	var resArr=IO.resHash[v];
	if(!resArr&&IO.resFrameHash[this.src]){
		this.src+="."+IO.resFrameHash[this.src];
		resArr=IO.resHash[this.src];
	}
	var n=this.src.lastIndexOf(".");
	this._frame=this.src.slice(-1)=="@"?0:Math.max(int(this.src.slice(n+1)),1);
	if(v.indexOf("/")>-1){
		this.w=100;
		this.h=100;
	}
	else if(resArr){
		this.w=resArr[2];
		this.h=resArr[3];
		if(resArr.length>=6){
			this.pivot=[resArr[4],resArr[5]];
		}
	}
	this.setSize(this.w,this.h);
}
public function setLoadSrc(v){
	this.loadSrc=v;
	var image=new Image();
	image.src=this.loadSrc;
	image.self=this;
	image.onload=this.onSrcLoad;
}
public function setFrame(f){
	var src=this.src;
	if(src.slice(-1)=="@"){
		if(f==1) this.setSrc(src.slice(0,-1));
		return;
	}
	else if(IO.resHash[src+"@"]){
		if(f==0) this.setSrc(src+"@");
		return;
	}
	var n=src.lastIndexOf(".");
	src=src.slice(0,n)+"."+f;
	if(src!=this.src){
		this.setSrc(src);
	}
}
public function setGrid9(v){
	if(!this.src) return;
	this.grid9=v;
	if(!G.style[this.src]) G.style[this.src]={};
	var style=G.style[this.src];
	style.grid9=v;
}
function onSrcLoad(evt){
	var image=evt.target;
	var self=image.self;
	var w=!self.loadSize?0:int(self.loadSize[0]);
	var h=!self.loadSize?0:int(self.loadSize[1]);
	var isAuto=!self.loadSize?false:self.loadSize[2];
	if(w==0&&h==0){
		w=image.width;
		h=image.height;
	}
	else if(w==0){
		w=h*image.width/image.height;
	}
	else if(h==0){
		h=w*image.height/image.width;
	}
	else if(isAuto){
		w=w/h>image.width/image.height?Math.ceil(h*image.width/image.height):w;
		h=w/h>image.width/image.height?h:Math.ceil(w*image.height/image.width);
	}
	self.setSrc(image.src);
	self.setSize(w,h);
	if(is(String,self.__x)||is(String,self.__y)){
		self.setPos(self.__x,self.__y);
	}
}